<template>
  <div>
    <el-table
      :data="menuList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"></el-table-column>
      <el-table-column label="菜单图标">
        <template v-slot="scoped">
          <div>
            <i :class="scoped.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status == 1"
              >启用</el-button
            >
            <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template v-slot="scoped">
          <div>
            <el-button @click="edit(scoped.row.id)">编辑</el-button>
            <el-button @click="del(scoped.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {sucessAlert,warningAlert} from "../../../utils/alert.js"
import {menuDel} from "../../../request/api.js"

export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      menuList:"menu/list",
    }),
  },
  methods: {
    ...mapActions({
        asyncMenuList:"menu/asyncList",
 
    }),
    del(id){
         this.$confirm('此操作将永久删除该文件，是否继续？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type:"warning"
        }).then(() =>
         {
                //点击成功
          menuDel({
                  id:id
                }).then(res=>{
                    if(res.data.code == 200){
                // 成功的提示窗
                sucessAlert(res.data.msg),
                // 刷新列表数据
                   this.asyncMenuList()
            }else{
                // 失败的提示窗
                warningAlert(res.data.msg)
            }
                })
          }).catch(()=> {

            // 如果走的catch说明点的是取消
             warningAlert("已取消删除")
          
          });
      },
    edit(id){
      this.$emit("edit",id)
    }
    },
  mounted() {
    
      this.asyncMenuList()

    }
}
  
</script>
<style scoped>
</style>